<template>
  <div>
    <van-nav-bar
      title="医院"
      left-arrow
      @click-left="backClick"
    />
    <div id="allmap" style="width: 100%;height:575px;"></div>
    <div class="more" @click="more">点击查看更多</div>
  </div>
</template>
<script>
import BMap from 'BMap'
import BMapLib from 'BMapLib'
import BMapSymbolSHAPEPOINT from 'BMap_Symbol_SHAPE_POINT'
export default{
  data(){
  return {
    pointArr:[]
    }
  },
  mounted(){
    this.createMap()
  },
  methods: {
    createMap () {
      this.$nextTick(function () {
         let _this = this
            //在此调用api
         let map = new BMap.Map("allmap") // 创建Map实例
        // map.enableScrollWheelZoom(true);
       //  map.enableDragging();   //两秒后开启拖拽
        map.enableScrollWheelZoom(true);
        map.setZoom(20);
        map.enableDragging();
         map.centerAndZoom(new BMap.Point(116.331398,39.897445), 15)
         let data_info = [[114.0555928,22.55173057,"地址：深圳市福田区第二人民医院"],
                     [114.0764173,22.57458844,"地址：深圳市社会福利中心康复医院"],
                     [113.9301215,22.536319,"地址：深圳市第六人民医院"],
                     [114.0609165,22.5530529,"地址：深圳市儿童医院"],
                     [114.0558054,22.56209804,"地址：北京大学深圳医院"],
                     [114.1009633,22.55609517,"地址：深圳市妇幼保健院（红荔路）"]
                    ];
        let local = new BMap.LocalSearch(map, {
            renderOptions: {map: map, autoViewport: true}
        })
        for(let i=0;i<data_info.length;i++){
          let marker = new BMap.Marker(new BMap.Point(data_info[i][0],data_info[i][1]));  // 创建标注
          let content = data_info[i][2];
          map.addOverlay(marker);               // 将标注添加到地图中
          addClickHandler(content,marker);
        }
        function addClickHandler(content,marker){
           marker.addEventListener("click",function(e){
             openInfo(content,e)}
          );
        }
        function openInfo(content,e){
          var p = e.target;
          var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
          var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
          map.openInfoWindow(infoWindow,point); //开启信息窗口
        }
      })
    },
    backClick () {
        //this.$router.push('/stageProducts/serviceType')
    },
    more () {
       // this.$router.push('/stageProducts/address-list')
    }
  }
}
</script>

<style lang="less" scoped>
.block {
    width: 318px;
    height: 100%;
    background: #f2f2f2;
    position: absolute;
    left: 0;
    top: 0;
    box-shadow: 3px 3px 3px #ccc;
    color: #ccc;
    .s_block {
        width: 318px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate3d(-50%, -50%, 0);
        text-align: center;
        line-height: 30px;
        button {
            background: #328ff7;
            color: #fff;
            border: none;
            border-radius: 5px;
            height: 25px;
            cursor: pointer;
        }

    }
}
.more {
    text-align: center;
    font-size: .16rem;
    line-height: .4rem
}
</style>
